<?php
session_start();
define('FPDF_FONTPATH','../pdf/font/');
require('../pdf/fpdf.php');
include('../funct.php');


    



$pdf=new FPDF();
$pdf->AddFont('Calligrapher','','arial_ce.php');
$pdf->AddPage();
$pdf->Image('../img/logo.png',165,8,33);
$pdf->SetFont('Calligrapher','',9);
$pdf->Text(10, 10, iconv('UTF-8','windows-1250//TRANSLIT',"NIEPUBLICZNY ZAKŁAD OPIEKI ZDROWOTNEJ"));
$pdf->Text(30, 13, "DARMEDICUS");
$pdf->SetFont('Calligrapher','',8);
$pdf->Text(18, 16, "04-364 Warszawa, ul. Wiatraczna 15 lok - U1");
$pdf->Text(29, 19, "tel/fax (22) 465 17 91");

$pdf->SetFont('Calligrapher','',14);
$pdf->Ln(15);
$pdf->MultiCell(0,10,'Grafik lekarzy w dniu '.$_SESSION['data'], 0, "C");

$sql="select wizyty.id_gab, sl_gab.nazwa from wizyty, sl_gab where wizyty.id_gab = sl_gab.id and wizyty.data like '".date("Y-m-d", strtotime($_SESSION['data']))."%' ";

$result=mysql_query($sql);
$ile_gab=mysql_num_rows ($result);
while($row = mysql_fetch_array($result))
{
$lista_gab[$row[0]]=$row[1];
}
if ($lista_gab=='') {
    $pdf->Ln(5);
    $pdf->MultiCell(0, 10, iconv('UTF-8','windows-1250//TRANSLIT','Brak lekarzy przyjmujących w danym dniu'));
}
else {
$nr_l=1;
$pdf->SetFont('Calligrapher','',8);
foreach ($lista_gab as $in =>$wa){
    $pdf->Ln(5);
    $pdf->MultiCell(0, 4, iconv('UTF-8','windows-1250//TRANSLIT',$wa), 0, 'C');
    $header = array('Godzina:', 'Pacjent:');
    
    $sql1="select wizyty.data, pac.pac_nazwisko, pac.pac_imie, wizyty.id, wizyty.id_pac, sl_uslugi.nazwa, sl_firmy.kolor from 
wizyty left join pac on pac.id = wizyty.id_pac
left join  sl_uslugi on sl_uslugi.id = wizyty.typ_wiz
left join sl_firmy on sl_uslugi.id_firmy = sl_firmy.id
where wizyty.data like '".$_SESSION['data']."%' and wizyty.akt = 1 and wizyty.id_gab = ".$in." order by wizyty.data";
    $nr=0;
    $result1=mysql_query($sql1);
    while($row2 = mysql_fetch_array($result1))
	{
    $data[$nr][0]=date("H:i", strtotime($row2[0]));
    $data[$nr][1]=$row2[1].' '.$row2[2].'-'.$row2[5];
    $nr++;
    
}
//$data=array("05:44", "Jasio");
// Header
    
        $pdf->Cell(16,4,$header[0],1, 'C');
        $pdf->Cell(174,4,$header[1],1);
        $pdf->Ln();
    // Data
 foreach($data as $row => $val)
 {
    
    $pdf->Cell(16,4,iconv('UTF-8','windows-1250//TRANSLIT',$val[0]),1);
    $pdf->Cell(174,4,iconv('UTF-8','windows-1250//TRANSLIT',$val[1]),1);
    $pdf->Ln();
    }
    unset($data);
    
}
}

$pdf->Output();
?>
